/*
Christopher Raffaele
02/18/2010
CSC280
Assignement 2 Towers of Hanoi

main.cpp
*/
#include<iostream>
#include<string>
#include"HanoiGame.h"

using namespace std;

int main(){
	cout << "------TOWERS OF HANOI-------------------------------------\n\n";

	unsigned int disks = 0;

	cout << "Enter the number of disks desired: ";

	//get user input for number of disks
	while(disks < 1){
		if(!(cin >> disks)){
			cin.clear();
			cin.ignore(10000,'\n');
			disks = 0;
		}
	}

	cout << endl;

	//create the game
	HanoiGame game1(disks);

	//display the initial configuration
	cout << game1;

	string answer = "";

	//check whether to auto-solve
	cout << "\nAuto-solve(y/n)? ";

	do{
		answer = "";
		getline(cin, answer);
	}while(answer[0] != 'y' && answer[0] != 'n');

	cout << endl;

	//autosolve
	if(answer[0] == 'y'){
		game1.Solve(disks, 'a', 'c', 'b');
		cout << game1;
	//manual solve
	}else{
		do{
			string from = "";
			string to = "";

			//get from/to tower input
			cout << "\nFrom tower(a, b, c): ";

			do{
				from = "";
				getline(cin, from);
			}while(from[0] != 'a' && from[0] != 'b' && from[0] != 'c');

			cout << "\nTo tower(a, b, c): ";

			do{
				to = "";
				getline(cin, to);
			}while(to[0] != 'a' && to[0] != 'b' && to[0] != 'c');

			//perform swap
			game1.Swap(from[0], to[0]);

			//show the new game configuration
			cout << "\n" << game1;

			//do until the game is finished
		}while(!game1.Finished());
	}
 
	cout << "\nGame Complete!" << endl;

	system("pause");
	return 0;
}